<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0072)http://www.mantisatemplates.com/template-preview/various/math/index.html -->
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Home</title>
        <!-- CSS --> 
        <link rel="stylesheet" href="ressorces/default.css" type="text/css" media="screen, projection, tv"/>
        <link rel="stylesheet" href="ressorces/print.css" type="text/css" media="print"/>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
        <script src="ressorces/jquery.tmp.js" type="text/javascript"></script>
        <script type="text/javascript" src="ressorces/utils.js"></script>
        <!-- Favicon -->
        <script type="text/javascript">

            $(document).ready(function() {
                var key = $.urlParam('key');
                var key = decodeURIComponent(key);
                key = change_alias(key);
                var page = $.urlParam('page');
                console.log(page);
                $('#search_button').click(function(e) {
                    $('form.searching').submit();
                    e.preventDefault();
                });
                $.ajax({
                    url: "menuService",
                    contentType: "application/json",
                    type: "get",
                    success: function(res) {
                        var element = res.data;
                        $('#list').tmpl(element).appendTo($('div.col-l-in'));
                    }
                });

                if (key == 0) {
                    $.ajax({
                        url: "postService",
                        contentType: "application/json",
                        type: "get",
                        data: "method=getLisForIndex",
                        success: function(res,abx,efg) {
                            console.log("vao day");
                            console.log(typeof res);
                            if(typeof res === "object"){
                                console.log("json");
                            } else {
                                console.log("string");
                            }
                            console.log(efg);
                            var element = res.data;
                            $('#post_index').tmpl(element).appendTo($('#post_index_content'));
                        }
                    });
                } else {
                    $.ajax({
                        url: "postService",
                        contentType: "application/json",
                        type: "get",
                        data: "method=getListForSearch&key=" + key,
                        success: function(res) {
                            var element = res.data.listPost;
                            console.log(element.length);
                            if (element.length > 0) {
                                $('#post_index').tmpl(element).appendTo($('#post_index_content'));
                                console.log(res.data.total);
                                pager(res.data.total);
                            } else {

                                $("<center><b>No Result</b></center>").appendTo($('#post_index_content'));

                            }

                            $("span:contains('Bài mới viết')").text("Kết quả tìm kiếm (" + res.data.total + ")");

                        }
                    });

                }
                $(document).ajaxComplete(function() {
                    $("div.article:odd").addClass("article-zebra");
                });
            });</script>
        <script id="list" type="text/x-jquery-tmpl">
            <h3>{{= name}}</h3>
            <ul class="menu">
            {{each listCate}}
            <li><a href="index?goto=categories&id={{= id}}"> {{= name}}</a> </li>     
            {{/each}}
            </ul>
        </script>

        <script id="post_index" type="text/x-jquery-tmpl">
            <div class="article">
            <h3  class="tile_content">{{= name}}</h3>
            <p>{{= content}}</p>
            <a class="more" href="index?goto=categories&id={{= categoriesId}}&postID={{= id}}">Read more</a>
            </div> 
        </script>

        <link rel="shortcut icon" href="http://www.mantisatemplates.com/template-preview/various/math/favicon.ico" type="image/x-icon">
            <style type="text/css"></style></head>

    <body id="top">
        <div id="wrapper">

            <%@ include file="header.jsp" %>

            <hr class="noscreen">

                <div id="skip-menu"></div>
                <div class="page">

                    <%@ include file="jsp/content_index.jsp" %>
                    <hr class="noscreen">

                        <div class="col-l">
                            <div class="col-l-in">

                            </div>
                            <script type="text/javascript">
                            </script>
                        </div> <!-- Left column end -->

                        <div class="cleaner">&nbsp;</div>

                </div> <!-- Page end -->

                <%@ include file="footer.jsp" %>
        </div>
        <p id="backlinks"><a href=""> Copyright &copy; Anh Dinh</a></p>


    </body></html>